package pers.qianyu.month_202012.date_20201221;

import org.junit.*;

/**
 * 746. 使用最小花费爬楼梯
 * https://leetcode-cn.com/problems/min-cost-climbing-stairs/
 *
 * @author mizzle rain
 * @date 2020-12-21 17:49
 */
public class MinCostClimbingStairs {
    public int minCostClimbingStairs(int[] cost) {
        int len = cost.length;
        // dp[i] 表示最后一个台阶是 i 的情况下，最小消耗的体力
        int[] dp = new int[len];
        dp[0] = cost[0];
        dp[1] = cost[1];
        for (int i = 2; i < len; i++) {
            dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];
        }
        //System.out.println(Arrays.toString(dp));
        return Math.min(dp[len - 1], dp[len - 2]);
    }

    @Test
    public void test1() {
        int[] arr = {0, 1, 1, 0};
        int r = new MinCostClimbingStairs().minCostClimbingStairs(arr);
        Assert.assertEquals(r, 1);
    }

    @Test
    public void test2() {
        int[] arr = {0, 0, 0, 1};
        int r = new MinCostClimbingStairs().minCostClimbingStairs(arr);
        Assert.assertEquals(r, 0);
    }
}
